package com.jiayi.weiphoto.page;


import com.jiayi.weiphoto.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MyImageVew extends ImageView implements AnimationListener{
	AnimationSet alphaAn;
	boolean animFlag = false;
	Bitmap iconBitmap;
	boolean loaded = false;
	public MyImageVew(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		alphaAn = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.alpha);
		alphaAn.setAnimationListener(this);
	}
	
	public MyImageVew(Context context){
		super(context);
		alphaAn = (AnimationSet) AnimationUtils.loadAnimation(context, R.anim.alpha);
		
	}

	public void setImageBitmapAnimationed(Bitmap bm) {
		// TODO Auto-generated method stub
		if(!loaded){
			this.iconBitmap = bm;
			alphaAn.reset();
			alphaAn.start();
			this.setAnimation(alphaAn);
			alphaAn.setFillAfter(true);
			loaded = true;
		}
		super.setImageBitmap(bm);
	}
	
	public void setAnimatedBitmapNoDelay(Bitmap bm){
			alphaAn.reset();
			this.setAnimation(alphaAn);
			super.setImageBitmap(bm);
			this.startAnimation(alphaAn);
	}

	@Override
	public void onAnimationEnd(Animation animation) {
		// TODO Auto-generated method stub
		animFlag = false;
	}

	@Override
	public void onAnimationRepeat(Animation animation) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onAnimationStart(Animation animation) {
		// TODO Auto-generated method stub
		animFlag = true;
	}
	
	@Override
	public void requestLayout() {
		// TODO Auto-generated method stub
	}
	
	
}
